package com.qingdai.business.utils;

import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Component
public class TimeUtil {
    public String getNow() {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
        LocalDateTime dateTime = LocalDateTime.now();
        String formattedDateTime = dateTime.format(formatter);
        return formattedDateTime;
    }

    //    2024-02-26 10:00:00——2024-02-28 10:00:00
    public Boolean effectiveCheck(String effective) {
        String[] s = effective.split("——");
        String startStr = s[0];
        String startEnd = s[1];
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime start = LocalDateTime.parse(startStr, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        LocalDateTime end = LocalDateTime.parse(startEnd, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        if (now.isAfter(start) && now.isBefore(end)) {
            return true;
        }
        return false;
    }
}
